home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: atom.ansto.gov.au!teslab!andrew
- From: andrew@teslab.lab.oz.au (Andrew Phillips)
- Subject: How to handle error in constructor
- Organization: Technology Services, Research, Sydney
- Date: Tue, 30 Jan 1996 00:54:21 GMT
- Message-ID: <DLyyIM.5EG@teslab.lab.oz.au>
- X-Newsreader: TIN [version 1.2 PL0]
-
- I'm converting and enhancing a simple program in C to C++. Without going
- into too much detail I have a class that represents a file on disk. The
- contructor opens the file, but what should it do if the file cannot be
- opened? The C program just calls fopen() tests the return value and
- if there's an error it prints a message and exits.
-
- In C++ I thought to set a flag in the constructor and have a member function
- that tests the flag to see if the file was opened correctly. This seems
- rather inelegant -- I guess exceptions would be the elegant way but seem
- like overkill for such a simple program. I've looked in several C++ books but
- error handling is given scant coverage except for exception handling.
-
- Any suggestions would be greatly appreciated.
-
- --
- Andrew Phillips (News/Sys Admin) andrew@teslab.lab.oz.au +61 2 287 6551
- --------------------------------
- Just a SPOKE, not a SPOKESPERSON
-